using UnityEngine;
using System.Collections;

[RequireComponent(typeof(NavMeshAgent))]
public class IA : MonoBehaviour
{
	 NavMeshAgent agent;
	 int i = 0;
	 public Transform[] destination;
	 
	 void Start()
	 {
	  this.agent = this.GetComponent<NavMeshAgent>();
	  this.agent.SetDestination(this.destination[i].position);
	 }
	 
	 void OnTriggerEnter(Collider other)
	 {
	  if(other.transform.GetInstanceID() != this.destination[i].GetInstanceID())
	   return;
	StartCoroutine("NextDestination");
	}
	IEnumerator NextDestination(){
		yield return new WaitForSeconds(2);
		i++;
	  if(i >= this.destination.Length)
	   i = 0;
	  this.agent.SetDestination(this.destination[i].position);
 }
}